<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript" src="<c:url value="/js/plug/area/load_area.js" />"></script>
<c:set var="buyerAddressId" value="${param.buyerAddressId}"></c:set>
<div class="easyui-layout" style="width:100%;height:100%;" fit="true">
	 	<div class="easyui-tabs"  data-options="tools:'#tab-tools',plain:true,region:'center',title:'',border:false" style="margin-top: 20px;" >
               <form id="drugBillInfo" method="post" >
               <table   border="0" cellspacing="0" cellpadding="0" style="margin: 10px;border-top: 1px solid #ddd;">
                      <tr>
                        <td class="table_td">收货人姓名</td>
                        <td class="juleft"><input id="consignee" name="consignee" class="easyui-validatebox" data-options="required:true,validType:'consignee'" missingMessage='该输入项为必输项'></td>
                      </tr>
                      <tr>
                        <td class="table_td">联系电话</td>
                        <td class="juleft"><input id="phone" name="phone" class="easyui-validatebox" data-options="required:true,validType:'mobile'" ></td>
                      </tr>
                      <tr>
                        <td class="table_td">收货地址</td>
                        <td class="juleft">
                       	   <div id="loc" >
     		                  <select name="province" id="province" style="width:100px;">
     		                     <option value="0">选择省</option>
     		                  </select>   
     		                  <select name="city" id="city" style="width:100px;">
     		                     <option value="0">选择市</option>
     		                  </select>   
     		                  <select name="district" id="district" style="width:100px;">
     		                     <option value="0">选择地区</option>
     		                  </select>
     	                  </div>
     	                  <input type="hidden" id="areaCode" name="areaCode" data-options="required:true" >
                          <input type="hidden" id="areaName" name="areaName" data-options="required:true" >
                        </td>
                      </tr>
                      <tr>
                        <td class="table_td">街道地址</td>
                        <td class="juleft"><input id="address" name="address" class="easyui-validatebox" style="width:350px" data-options="validType:'address'"></td>
                      </tr>
                       <tr>
                        <td class="table_td">邮编</td>
                        <td class="juleft"><input id="zip" name="zip" class="easyui-validatebox"  data-options="validType:'zip'"></td>
                      </tr>
                      <tr>
                        <td></td>
                        <td style="padding-top:10px; border:0">
                        <input type="checkbox" id="checkboxForDefalut" name="checkboxForDefalut">设置为默认地址
                        <input type="hidden" id="isDefalut" name="isDefalut">
                        </td>
                      </tr>
                     <tr>
					   <td colspan="4" align="center">
						<input type="button" onclick="submitForm()" class="button" data-options="iconCls:'icon-save'" value="提交" >
						<input type="button" onclick="pms.resetForm('drugBillInfo')" class="button" data-options="iconCls:'icon-save'" value="重置" >
					    </td>
				     </tr>
              </table>
           </form>	  
	</div>   
<script>

$("#loc").LocationSelect({
	data:"<c:url value='/js/plug/area/areas.json' />"
});
	
function submitForm(){
	$('#drugBillInfo').form('submit', {
	    url:'<c:url value="/buyerAddress/addBuyerAddress.s"/>',
	    onSubmit: function(param){
	    	//areaCode赋值
	        var value_province = $("#province").val();
	        var value_city = $("#city").val();
	        var value_district = $("#district").val();
	        var text_province = $('#province option:selected').text();
	        var text_city = $('#city option:selected').text();
	        var text_district = $('#district option:selected').text();
	        if(value_district != "0"){
	        	$("#areaCode").val(value_district);
	        	$("#areaName").val(text_province+text_city+text_district);
	        }else if(value_city != "0"){
	        	$("#areaCode").val(value_city);
	        	$("#areaName").val(text_province+text_city);
	        }else if(value_province != "0"){
	        	$("#areaCode").val(value_province);
	        	$("#areaName").val(text_province);
	        }else{
	        	return false;
	        }
	        //判断是否为默认地址
	        if(document.getElementById("checkboxForDefalut").checked){	
	        	$("#isDefalut").val("1");
	        }else{
	        	$("#isDefalut").val("0");
	        }
	        
	    	if(!$("#drugBillInfo").form('validate')){
	    		return false;
	    	}
	    },
	    success:function(data){
	    	var ret = eval("("+data+")");
	     	if(ret.code=="200"){
	     		 layer.msg("新增成功",1, {type: 1,shade: [0.2, '#ccc']});
	     		$("#win_address_add").dialog('close');
	     		addressTable.refresh();
		    }else{
		    	layer.msg(ret.result);
			}
	    }
	});
}
function test(){
	$("#consignee").val("糖糖");
	$("#phone").val("18258802774");
	$("#address").val("中山北路8号");
	$("#zip").val("310000");
	}
</script>